layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func', 'laydate', 'upload'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var laydate = layui.laydate;
    var upload = layui.upload;

    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格idbtyDdpx.html
    };

    //渲染时间选择框
    laydate.render({
        elem: '#loanDate',
        range: true,
        trigger: 'click'
    });

    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', align: "center", sort: true, title: '员工id'},
            {field: 'name', align: "center", sort: true, title: '学员姓名'},
            {field: 'bm', align: "center", sort: true, title: '部门'},
            {field: 'ks', align: "center", sort: true, title: '考试'},
            {field: 'tgqk', align: "center", sort: true, title: '通过情况'},
            {field: 'date', align: "center", sort: true, title: '通过时间'},
            {field: 'yyjl', align: "center", sort: true, title: '营运经理'},
            {field: 'dd', align: "center", sort: true, title: '督导'},
        ]];
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/btyDdpx/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        limit: 20,
        skin: 'line',
        cols: Notice.initColumn(),
    });

    /**
     * 导入Excel
     */
    var loadIndex;
    upload.render({
        elem: '#btnExcel'
        , url: '/btyDdpx/import'
        , accept: "file"
        , async: false
        , exts: 'xls|xlsx|xlsm|xlt|xltx|xltm'
        , before: function () {
            loadIndex = layer.load(2, {shade: [0.15, '#ccc']});
        }
        , done: function (res) {
            if (res == 0) {
                layer.msg('导入失败！', {icon: 1, time: 2000, shade: 0.2});
            } else {
                layer.msg('导入成功！', {icon: 1, time: 2000, shade: 0.2});
                /*table.reload(Notice.tableId, {
                    page: {curr: 1}
                });*/
            }
            window.location.reload();
            layer.close(loadIndex);
        }
    });

    /**
     * 导出excel按钮
     */
    Notice.exportExcel = function () {
        //获取导出的数据
        var ajax = new $ax(Feng.ctxPath + "/btyDdpx/listAll");
        var result = ajax.start();
        table.exportFile(tableResult.config.id, result, 'xls');
    };

    // 点击导出excel
    $('#download').click(function () {
        Notice.exportExcel();
    });
});
